﻿using System;
using System.Reflection;
using DictToObject.Helpers;

namespace DictToObject.Factories
{
    public interface IFieldLikeMemberFactory
    {
        IFieldLikeMember Create(MemberInfo info);
    }

    public class FieldLikeMemberFactory : IFieldLikeMemberFactory
    {
        public IFieldLikeMember Create(MemberInfo info)
        {
            if (info is FieldInfo)
                return new FieldMember((FieldInfo) info);
            if (info is PropertyInfo)
                return new PropertyMember((PropertyInfo) info);
            throw new ArgumentException("FieldInfo or PropertyInfo expected");
        }
    }
}